package com.example.mvp.view;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.example.mvp.R;
import com.example.mvp.presenter.UserLoginPresenter;

public class LoginActivity extends AppCompatActivity implements IUserLoginView{
    private EditText mEdtName;
    private EditText mEdtPwd;
    private ProgressBar mProgressBar;
    private Button mClearNameBt,mClearPwdBt;

    private UserLoginPresenter mulp=new UserLoginPresenter(this);



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initViews();
    }

    private void initViews() {
        mEdtName = (EditText) findViewById(R.id.edt_name);
        mEdtPwd = (EditText) findViewById(R.id.edt_pwd);
        mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
        mClearNameBt = (Button) findViewById(R.id.clear_name_bt);
        mClearPwdBt = (Button) findViewById(R.id.clear_pwd_bt);

        mClearNameBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mulp.login();
            }
        });

        mClearPwdBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mulp.clear();
            }
        });
    }

    @Override
    public String getUsername() {
        return mEdtName.getText().toString();
    }

    @Override
    public String getUserpwd() {
        return mEdtPwd.getText().toString();
    }

    @Override
    public void showLoding() {
        mProgressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideLoding() {
        mProgressBar.setVisibility(View.GONE);
    }

    @Override
    public void toSuccessActivity() {
        Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
        Intent intent=new Intent(this,SuccessActivity.class);
        startActivity(intent);
    }

    @Override
    public void showFailedError() {
        Toast.makeText(this, "登录失败", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void clearUsername() {
        mEdtName.setText("");
    }

    @Override
    public void clearUserpwd() {
        mEdtPwd.setText("");
    }
}
